package com.ksd.quartz.task;

import com.ksd.common.utils.StringUtils;
import com.ksd.system.domain.SysFirst;
import com.ksd.system.service.ISysFirstService;
import com.ksd.system.service.impl.AsynchWeatherService;
import com.ksd.system.service.impl.SysBoardServiceImpl;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 每隔8小时更新一遍城市的最新天气
 */
@Component
@EnableScheduling
public class SynchWeatherTask {

    private static final Logger logger = org.slf4j.LoggerFactory.getLogger(SynchWeatherTask.class);

    @Autowired
    private ISysFirstService sysFirstService;
    @Autowired
    private AsynchWeatherService asynchWeatherService;


    @Scheduled(cron = "0 0 */8 * * ?")
    public void getCityNewWeather()
    {
        logger.info("同步更新城市最新天气情况");
        SysFirst sysFirst = sysFirstService.selectSysFirstById(SysFirst.weather);
        if (StringUtils.isNotNull(sysFirst)) {
            asynchWeatherService.updateCityWeather(sysFirst);
        }

    }

}
